Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatic typeclass derivation #447

Merged
merged 5 commits into from
Mar 5, 2018
Merged

automatic typeclass derivation #447

merged 5 commits into from
Mar 5, 2018

Conversation

fommil
Copy link
Contributor

@fommil fommil commented Mar 1, 2018

https://gitlab.com/fommil/scalaz-deriving/issues/56

we can also do covariant functors if the provide a MonadError[?, String] but I'm encountering some implicit problems... so raising this PR to discuss.

@fommil fommil changed the title WIP: automatic typeclass derivation for contravariant functors automatic typeclass derivation for contravariant functors Mar 3, 2018
@fommil fommil changed the title automatic typeclass derivation for contravariant functors automatic typeclass derivation Mar 3, 2018
@codecov-io
Copy link

codecov-io commented Mar 3, 2018

Codecov Report

Merging #447 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #447      +/-   ##
==========================================
+ Coverage   98.01%   98.03%   +0.01%     
==========================================
  Files          57       57              
  Lines         655      660       +5     
  Branches       12       12              
==========================================
+ Hits          642      647       +5     
  Misses         13       13
Impacted Files Coverage Δ
...main/scala/eu/timepit/refined/scalaz/package.scala 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2366c6d...e03521c. Read the comment docs.

@fommil
Copy link
Contributor Author

fommil commented Mar 3, 2018

I think I need a few SAM type hints to keep the older scala versions happy. Or just not use SAM types.

@fommil
Copy link
Contributor Author

fommil commented Mar 3, 2018

the 2.10 compile error is happening in a file I didn't touch... what's going on?

@fthomas
Copy link
Owner

fthomas commented Mar 4, 2018

The first error in the 2.10 build is

[info] Compiling 4 Scala sources to /home/travis/build/fthomas/refined/modules/scalaz/js/target/scala-2.10/test-classes ...
[error] /home/travis/build/fthomas/refined/modules/scalaz/shared/src/test/scala/eu/timepit/refined/scalaz/RefTypeSpecScalazMonadError.scala:48:26: diverging implicit expansion for type eu.timepit.refined.scalaz.Decoder[eu.timepit.refined.api.Refined[String,eu.timepit.refined.collection.NonEmpty]]
[error] starting with method refTypeContravariant in package scalaz
[error]     val decoder = Decoder[String Refined NonEmpty]
[error]                          ^

which is in a file you've added :-)

@fommil
Copy link
Contributor Author

fommil commented Mar 4, 2018

@fthomas heh, yeah but one of the other files is also failing. I think 2.10's implicit resolution is just not good enough for this derivation. If you can think of a hack, that would be good, otherwise perhaps we should make this 2.11+ only?

fthomas added a commit that referenced this pull request Mar 4, 2018
@fthomas fthomas mentioned this pull request Mar 4, 2018
@fthomas
Copy link
Owner

fthomas commented Mar 4, 2018

I tried shuffling the instances around but that didn't make a difference. I'm fine with making that 2.11+ only.

@fommil
Copy link
Contributor Author

fommil commented Mar 5, 2018

@fthomas green lights!

@fthomas
Copy link
Owner

fthomas commented Mar 5, 2018

Looks great, many thanks @fommil!

This is also a great example how to combine type classes via abstractions like Contravariant and MonadError. I find it fascinating that we can express these relationships in code.

@fthomas fthomas merged commit 609cbe3 into fthomas:master Mar 5, 2018
@fommil fommil deleted the scalaz-deriving branch March 5, 2018 22:11
@fommil
Copy link
Contributor Author

fommil commented Mar 5, 2018

@fthomas I'm trying to explore as much of the automatic derivation space as possible for the Typeclass Derivation chapter of my book. It was really good fun figuring this out and supporting refined types turned out to be much more elegant than I'd hoped. Create an iso to a readert and you get free decodings, nice!

fthomas added a commit that referenced this pull request Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants